'''
@Project --> File: TFECUserProfile -> ESMate_demo1
@IDE: PyCharm
@Author: Burke
@Date: 2023/6/14
'''

from pyspark.sql import SparkSession
import os

# 明确指定pyspark使用的python环境
os.environ['SPARK_HOME'] = '/export/server/spark'
os.environ['PYSPARK_PYTHON'] = '/root/anaconda3/bin/python3'
os.environ['PYSPARK_DRIVER_PYTHON'] = '/root/anaconda3/bin/python3'


class ESMate(object):
#1- 声明数据
    inType : str
    esNodes : str
    esIndex : str
    esType : str
    selectFields : str
#2- 内置属性
    def __init__(self,inType,esNodes,esIndex,esType,selectFields):
        self.inType = inType
        self.esNodes = esNodes
        self.esIndex = esIndex
        self.esType = esType
        self.selectFields = selectFields

    def get_dict(dict:dict):
            return ESMate(
                dict.get("inType",""),
                dict.get("esNodes",""),
                dict.get("esIndex",""),
                dict.get("esType",""),
                dict.get("selectFields","")
            )
#3- 获取属性


if __name__ == '__main__':
    spark = SparkSession \
        .builder \
        .appName('ESMate_demo1') \
        .master('local[*]') \
        .getOrCreate()

    ruledict = {'inType': 'Elasticsearch',
                'esNodes':'up01:9200',
                'esIndex': 'tfec_tbl_users',
                'esType': '_doc',
                'selectFields': 'id,birthday'}

    data = ESMate.get_dict(ruledict)
    print(data.inType)
    print(data.esNodes)
    print(data.esIndex)
    print(data.esType)
    print(data.selectFields)